import { instance } from '@/http/index'
import { UpdateStatusDto } from '@/types/dto'
import { LabelValue } from '@/types/interface'
import { ApiResponseVo } from '@/types/vo'

import { MenuCriteria, MenuModalDto } from './type/dto'
import { MenuItem } from './type/vo'

/** ************** 增加( Create ) *******************/

export const createMenu = (data: MenuModalDto): Promise<ApiResponseVo> => instance.post('/menus/create', data)

/** ************** 读取( Read ) *******************/
export const getMenuAllTree = (): Promise<ApiResponseVo<LabelValue[]>> => instance.post('/menus/tree')

export const getMenuList = (data: MenuCriteria): Promise<ApiResponseVo<MenuItem[]>> =>
  instance.post('/menus/list', data)

/** ************** 修改( Update ) *******************/
export const updateMenu = (data: MenuModalDto): Promise<ApiResponseVo> => instance.post('/menus/update', data)

export const updateMenuStatus = (data: UpdateStatusDto): Promise<ApiResponseVo> => instance.post('/menus/status', data)

/** ************** 删除( Remove ) *******************/
export const deleteMenu = (data: { id: number }): Promise<ApiResponseVo> => instance.post('/menus/delete', data)
